﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Maticsoft.Common;

namespace Admin.WorkFlow.WorkFlowManage
{
    public partial class FlowAdd : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Expires = -1;
            if (!IsPostBack)
                BindRole();
        }

        private void BindRole()
        {
            ChinaSoft.BLL.BLL_tb_MidSoft_Roles bllRoles = new ChinaSoft.BLL.BLL_tb_MidSoft_Roles();
            ChinaSoft.Model.Model_tb_MidSoft_Roles modelRoles = new ChinaSoft.Model.Model_tb_MidSoft_Roles();
            System.Data.DataSet ds=bllRoles.GetAllList();
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                ddlRole.DataSource = ds;
                ddlRole.DataTextField = "RoleName";
                ddlRole.DataValueField = "RolesId";
                ddlRole.DataBind();
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            string strErr = "";
            if (this.txtFlowName.Text.Trim().Length == 0)
            {
                strErr += "流程名称不能为空！\\n";
            }
            if (this.txtNewForm.Text.Trim().Length == 0)
            {
                strErr += "新建表单不能为空！\\n";
            }
            if (this.txtEditForm.Text.Trim().Length == 0)
            {
                strErr += "编辑表单不能为空！\\n";
            }
            if (this.txtReadonlyForm.Text.Trim().Length == 0)
            {
                strErr += "只读表单不能为空！\\n";
            }
            if (this.ddlRole.SelectedItem.Value=="")
            {
                strErr += "流程启动角色不能为空！\\n";
            }
            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            string FlowName = this.txtFlowName.Text;
            string NewForm = this.txtNewForm.Text;
            string EditForm = this.txtEditForm.Text;
            string ReadonlyForm = this.txtReadonlyForm.Text;
            string StartRole = this.ddlRole.SelectedItem.Text;
            DateTime CreateTime = System.DateTime.Now;
            int CreateUserId = 5;

            ChinaSoft.Model.Model_tb_MidSoft_PmFlow model = new ChinaSoft.Model.Model_tb_MidSoft_PmFlow();
            model.FlowName = FlowName;
            model.NewForm = NewForm;
            model.EditForm = EditForm;
            model.ReadonlyForm = ReadonlyForm;
            model.StartRole = StartRole;
            model.CreateTime = CreateTime;
            model.CreateUserId = CreateUserId;

            ChinaSoft.BLL.BLL_tb_MidSoft_PmFlow bll = new ChinaSoft.BLL.BLL_tb_MidSoft_PmFlow();
            bll.Add(model);
            //Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功！", "FlowAdd.aspx");
            #region 添加项目流程
            ChinaSoft.Model.Model_tb_MidSoft_log modelLog = new ChinaSoft.Model.Model_tb_MidSoft_log();
            ChinaSoft.BLL.BLL_tb_MidSoft_log bllLog = new ChinaSoft.BLL.BLL_tb_MidSoft_log();
            modelLog.CreateTime = DateTime.Now;
            modelLog.userAccount = ChinaSoft.Common.Input.SetString(Session["UserAccount"]);
            modelLog.userName = ChinaSoft.Common.Input.SetString(Session["UserName"]);
            modelLog.LogType = 1;
            modelLog.description = "添加项目流程成功！";
            bllLog.Add(modelLog);
            #endregion
            Response.Write("<script>alert('成功！');top.window.parent.frames.item('workspace').location.reload();window.parent.$('#DivSysiframe').dialog(\"close\");</script>");
        }

    }
}